package com.jidesoft.example;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import com.jidesoft.icons.JideIconsFactory;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.JideBorderLayout;
import com.jidesoft.swing.JideBoxLayout;
import com.jidesoft.swing.JideSwingUtilities;
import com.jidesoft.swing.JideTabbedPane;

public class JideBoxLayoutDemo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		LookAndFeelFactory.installDefaultLookAndFeelAndExtension();

		JFrame frame = new JFrame("Test");
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.out.println("关闭");
			}
		});

		frame.setIconImage(JideIconsFactory.getImageIcon(
				JideIconsFactory.JIDE32).getImage());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.getContentPane().setLayout(new BorderLayout());
		frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER);

		frame.pack();
		JideSwingUtilities.globalCenterWindow(frame);
		frame.setVisible(true);
		frame.toFront();
	}

	public static Component getDemoPanel() {
		// create a panel with JideBoxLayout
		JPanel panel = new JPanel();
		panel.setLayout(new JideBoxLayout(panel, 0, 6));

		JButton button = new JButton("固定 (宽:120)");
		button.setPreferredSize(new Dimension(120, 200));
		button.setMinimumSize(new Dimension(0, 0));
		button.setMaximumSize(new Dimension(Integer.MAX_VALUE,
				Integer.MAX_VALUE));
		panel.add(button, JideBoxLayout.FIX);

		button = new JButton("灵活 (宽:120)");
		button.setPreferredSize(new Dimension(120, 200));
		button.setMinimumSize(new Dimension(0, 0));
		button.setMaximumSize(new Dimension(Integer.MAX_VALUE,
				Integer.MAX_VALUE));
		panel.add(button, JideBoxLayout.FLEXIBLE);

		button = new JButton("灵活 (宽:240)");
		button.setPreferredSize(new Dimension(240, 200));
		button.setMinimumSize(new Dimension(0, 0));
		button.setMaximumSize(new Dimension(Integer.MAX_VALUE,
				Integer.MAX_VALUE));
		panel.add(button, JideBoxLayout.FLEXIBLE);

		button = new JButton("VARY (宽:120)");
		button.setPreferredSize(new Dimension(120, 200));
		button.setMinimumSize(new Dimension(0, 0));
		button.setMaximumSize(new Dimension(Integer.MAX_VALUE,
				Integer.MAX_VALUE));
		panel.add(button, JideBoxLayout.VARY);

		panel.setBorder(new TitledBorder("缩放面板观察组件的缩放行为"));

		return panel;
	}

}
